package com.example.ffepeg.ffpeg;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson2.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class TestMain {

    private static ConcurrentHashMap<String, List<Vocabulary>> mapVo = new ConcurrentHashMap<>();
    public static void main(String[] args) {
       /* Vocabulary vo = new Vocabulary();
        vo.setVoca("H");
        vo.setSort(1);
        vo.setIdea("E");
        vo.setWord("LLO");
        Vocabulary vo1 = new Vocabulary();
        vo1.setVoca("P");
        vo1.setSort(2);
        vo1.setIdea("O");
        vo1.setWord("LL");
        List<Vocabulary> list = new ArrayList<>();
        list.add(vo);
        list.add(vo1);
        mapVo.put("key",list);
        List<Vocabulary> coList = mapVo.get("key");

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("wordClerk", vo);

        JSONObject jsonObject1 = JSONObject.parseObject(jsonObject.toJSONString());
        JSONObject jsonObject2 = JSONObject.parseObject(jsonObject1.get("wordClerk").toString());
        System.out.println(jsonObject2);
        System.out.println(jsonObject2.get("idea"));
        System.err.println(coList.size());*/

        int start = requestClerk.indexOf('[');
        int end = requestClerk.lastIndexOf(']');
        // 提取出 JSON 数组字符串
        if (start != -1 && end != -1 && start < end) {
            String jsonArrayStr = requestClerk.substring(start, end + 1);
            List<Vocabulary> vocabularieList = JSON.parseObject(jsonArrayStr, new TypeReference<List<Vocabulary>>() {});
            mapVo.put("key", vocabularieList);
            Vocabulary vocabulary = vocabularieList.get(0);
            System.out.println(vocabulary);
        }
    }

    private static String requestClerk = "{\n" +
            "  \"words\": [\n" +
            "    { \"sort\": 1, \"word\": \"clothes\", \"abbr\": \"clths\", \"voca\": \"noun\", \"idea\": \"衣物，服装\" },\n" +
            "    { \"sort\": 2, \"word\": \"garment\", \"abbr\": \"garmt\", \"voca\": \"noun\", \"idea\": \"衣服，服饰\" },\n" +
            "    { \"sort\": 3, \"word\": \"apparel\", \"abbr\": \"aprl\", \"voca\": \"noun\", \"idea\": \"服装，着装\" },\n" +
            "    { \"sort\": 4, \"word\": \"attire\", \"abbr\": \"atr\", \"voca\": \"noun\", \"idea\": \"穿着，打扮\" },\n" +
            "    { \"sort\": 5, \"word\": \"outfit\", \"abbr\": \"otft\", \"voca\": \"noun\", \"idea\": \"全套服装\" },\n" +
            "    { \"sort\": 6, \"word\": \"fashion\", \"abbr\": \"fshn\", \"voca\": \"noun\", \"idea\": \"时尚，流行样式\" },\n" +
            "    { \"sort\": 7, \"word\": \"style\", \"abbr\": \"stl\", \"voca\": \"noun\", \"idea\": \"风格，样式\" },\n" +
            "    { \"sort\": 8, \"word\": \"fabric\", \"abbr\": \"frbc\", \"voca\": \"noun\", \"idea\": \"织物，布料\" },\n" +
            "    { \"sort\": 9, \"word\": \"texture\", \"abbr\": \"txtr\", \"voca\": \"noun\", \"idea\": \"质地，纹理\" },\n" +
            "    { \"sort\": 10, \"word\": \"design\", \"abbr\": \"dsign\", \"voca\": \"noun\", \"idea\": \"设计，图案\" }\n" +
            "  ]\n" +
            "}\n" +
            "接下来，你可以选择开始语法练习！";


}
